#include "looplist.h"

LoopList::LoopList(uint32_t n)
{
	total = n;
	for(auto i = 0; i < n; i++) {
		shared_ptr<KCPPacket> nullObj;
		recvSlots.push_back(nullObj);
	}
}

void LoopList::AddPacket(shared_ptr<KCPPacket> pack, uint32_t index)
{
	auto id = (start + index) % (total);
	recvSlots[id] = pack;
}

shared_ptr<KCPPacket> LoopList::TakePacket() {
	auto cp = readPos;
	if(recvSlots[readPos] == nullptr) {
		return recvSlots[readPos];	
	}
	readPos++;
	readPos %= total;
	return recvSlots[cp];
}

void LoopList::MoveStart()
{
	shared_ptr<KCPPacket> nullObj;
	recvSlots[start] = nullObj;
	start++;
	start %= total;
}
